package com.bjc.core.controller;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.bjc.base.bean.ResultVO;
import com.bjc.base.core.ResultGenerator;
import com.bjc.base.core.annotation.PermissionPath;
import com.bjc.core.bean.request.EmailRecordReqVO;
import com.bjc.core.bean.response.EmailRecordVO;
import com.bjc.core.service.IEmailRecordService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

/**
 * 邮件发送记录
 * @author 许自辉
 * @date 2017年9月4日
 */
@RestController
@RequestMapping("api/cloud")
@PermissionPath("系统管理/邮件发送记录")
@Api(value = "emailRecord-api", tags = { "邮件发送记录相关接口" })
public class EmailRecordController {

	@Autowired
	private IEmailRecordService emailRecordService;

	@ApiOperation("分页查询邮件发送记录")
	@RequiresPermissions("emailRecord:findPage")
	@GetMapping("emailRecord/findPage")
	public ResultVO getLookupPage(@RequestParam("pageNum") int pageNum, @RequestParam("pageSize") int pageSize,
			EmailRecordReqVO reqVO) {
		PageHelper.startPage(pageNum, pageSize);
		List<EmailRecordVO> richTextVOs = emailRecordService.getList(reqVO);
		return ResultGenerator.getSuccess(new PageInfo<EmailRecordVO>(richTextVOs));
	}
	
	@ApiOperation("查询邮件发送记录")
	@RequiresPermissions("emailRecord:find")
	@GetMapping("emailRecord/find")
	public ResultVO getLookupPage(EmailRecordReqVO reqVO) {
		return ResultGenerator.getSuccess(emailRecordService.get(reqVO));
	}


	@ApiOperation("批量删除邮件发送记录")
	@RequiresPermissions("emailRecord:deleteList")
	@DeleteMapping("emailRecord/deleteList")
	public ResultVO deleteLookup(@ApiParam("lookupItem id集合") @RequestBody int[] ids) {
		int count = emailRecordService.deleteList(ids);
		return ResultGenerator.getDeleteSuccess(count);
	}
}
